<!DOCTYPE html>
<html lang="en">
<body>
<script>
    const m = new Map(
        [
            ['a', 1],
            ['b', 2],
            ['c', 3],
        ]
    )
    console.log(m.entries === m[Symbol.iterator]) // true
    console.log(Array.from(m[Symbol.iterator]()))

    // 1.for -of迭代  keys() values() entries()
    for (let [key, value] of m.entries()) {
    }
    // 2. ...迭代
    console.log([...m])
    // 3. forEach迭代
    m.forEach((value, key, theMap) => {

    })


    // 4.迭代遍历时,修改值的问题
    const m1 = new Map([['key1', 'val1']])
    for(let key of m1.keys()){
        key = 'newKey'
        console.log(key)
        console.log(m1.get('key1')) // val1 (很好理解吧)
    }


    // 修改了作为键的对象的属性，但对象在映射内部仍然引用相同的
    const keyObj = {id:1}
    const m2 = new Map([
        [keyObj,'val1']
    ])
    for(let key of m2.keys()){
        key.id = 'newKey'
        console.log(key)   // {id:'newKey'}
        console.log(m2.get(keyObj)); // val1
    }
    console.log(keyObj)  // {id:'newKey'}


</script>
</body>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
</html>